<?php	require_once(dirname(__FILE__).'/inc/config.inc.php');IsModelPriv('infolist');

/*
**************************
(C)2010-2015 phpMyWind.com
update: 2014-5-30 17:03:29
person: Feng
**************************
*/


//初始化参数
$tbname = '#@__infolist';
$gourl  = 'infolist.php';
$action = isset($action) ? $action : '';


//添加行业资讯
if($action == 'add')
{
	if ($_POST['lan'] == 'zh')
	{
		$classid = '15';
	}
	else
	{
		$classid = '16';
	}

	//初始化参数
	if(!isset($flag))          $flag   = '';

	//检查展示图片是否传了过来
	if($_FILES['picurl']['error'] == 0)
	{
		//判断是否是通过HTTP POST上传的
		if (!is_uploaded_file($_FILES['picurl']['tmp_name'])) {
			return ('非法上传');
		}

		//开始移动文件到相应的文件夹
		$upload_path = "../uploads/image/" . date('Ymd'); //上传文件的存放路径
		if (!file_exists($upload_path)) //检查文件是否存在
		{
			mkdir($upload_path);
		}

		//移动图片文件
		$picurl = $upload_path . '/' . time() . $_FILES['picurl']['name'];
		move_uploaded_file($_FILES['picurl']['tmp_name'], $picurl);
		$picurl = substr($picurl,3);
	}
	elseif($_FILES['picurl']['error'] == 1)
	{
		echo"<script>alert('缩略图片过大,最大2MB');history.go(-1);</script>";
	}
	elseif($_FILES['picurl']['error'] == 4)
	{
		echo '';
	}
	else
	{
		echo"<script>alert('缩略图片上传失败,请重试');history.go(-1);</script>";
	}

	$parentid = '';

	if($parentid == 0)
	{
		$parentstr = '0,';
	}
	else
	{
		$r = $dosql->GetOne("SELECT `parentstr` FROM `#@__infoclass` WHERE `id`=$parentid");
		$parentstr = $r['parentstr'].$parentid.',';
	}

	//文章属性
	if(is_array($flag))
	{
		$flag = implode(',',$flag);
	}

	$posttime = GetMkTime($posttime);

	//自定义字段处理
	$fieldname  = '';
	$fieldvalue = '';
	$fieldstr   = '';

	$sql = "INSERT INTO `$tbname` (siteid, classid, parentid, parentstr, mainid, mainpid, mainpstr, title, colorval, boldval, flag, source, author, linkurl, keywords, description, content, picurl, picarr, orderid, hits, posttime, checkinfo {$fieldname}) VALUES ('$cfg_siteid', '$classid', '3', '0,3,', '', '$mainpid', '$mainpstr', '$title', '', '', '$flag', '', '', '', '$keywords', '$description', '$content', '$picurl', '$picarr', '$orderid', '$hits', '$posttime', '$checkinfo' {$fieldvalue})";

	if($dosql->ExecNoneQuery($sql))
	{
		header("location:$gourl");
		exit();
	}
}


//修改行业资讯
else if($action == 'update')
{
	//初始化参数
	if(!isset($flag))          $flag   = '';

	//判断是否上传了图片
	if($_FILES['picurl']['error'] == 0)
	{
		//判断是否是通过HTTP POST上传的
		if(!is_uploaded_file($_FILES['picurl']['tmp_name']))
		{
			return('非法上传');
		}

		//开始移动文件到相应的文件夹
		$upload_path = "../uploads/image/".date('Ymd'); //上传文件的存放路径
		if (!file_exists($upload_path)) //检查文件是否存在
		{
			mkdir($upload_path);
		}

		//移动图片文件
		$picurl = $upload_path.'/'.time().$_FILES['picurl']['name'];
		move_uploaded_file($_FILES['picurl']['tmp_name'],$picurl);
		$picurl = substr($picurl,3);
	}
	elseif($_FILES['picurl']['error'] == 1)
	{
		echo"<script>alert('缩略图片过大,最大2MB');history.go(-1);</script>";
	}
	elseif ($_FILES['picurl']['error'] == 4)
	{
		$picurl = $_POST['picurl_bak'];
	}
	else
	{
		echo"<script>alert('上传失败,请重试');history.go(-1);</script>";
	}

	$parentid = '';

	if($parentid == 0)
	{
		$parentstr = '0,';
	}
	else
	{
		$r = $dosql->GetOne("SELECT `parentstr` FROM `#@__infoclass` WHERE `id`=$parentid");
		$parentstr = $r['parentstr'].$parentid.',';
	}

	//文章属性
	if(is_array($flag))
	{
		$flag = implode(',',$flag);
	}

	$posttime = GetMkTime($posttime);

	//自定义字段处理
	$fieldname  = '';
	$fieldvalue = '';
	$fieldstr   = '';

	$sql = "UPDATE `$tbname` SET siteid='$cfg_siteid', mainid='', mainpid='', mainpstr='', title='$title', colorval='', boldval='', flag='$flag', source='', author='', linkurl='', keywords='$keywords', description='$description', content='$content', picurl='$picurl', picarr='', orderid='$orderid', hits='$hits', posttime='$posttime', checkinfo='$checkinfo' {$fieldstr} WHERE id=$id";

	if($dosql->ExecNoneQuery($sql))
	{
		header("location:$gourl");
		exit();
	}
}


//修改审核状态
else if($action == 'check')
{
	//审核权限
	$r = $dosql->GetOne("SELECT `classid` FROM `#@__infolist` WHERE `id`=$id");
	IsCategoryPriv($r['classid'],'update');


	if($checkinfo == '已审')
	{
		$dosql->ExecNoneQuery("UPDATE `$tbname` SET `checkinfo`='false' WHERE `id`=$id");
		echo '<a href="javascript:;" onclick="CheckInfo('.$id.',\'未审\')" title="点击进行审核与未审操作">未审</a>';
		exit();
	}

	if($checkinfo == '未审')
	{
		$dosql->ExecNoneQuery("UPDATE `$tbname` SET `checkinfo`='true' WHERE `id`=$id");
		echo '<a href="javascript:;" onclick="CheckInfo('.$id.',\'已审\')" title="点击进行审核与未审操作">已审</a>';
		exit();
	}
}


//无状态返回
else
{
	header("location:$gourl");
	exit();
}
?>
